import axios from "axios";

/**
 * 必应图片数据
 */
class BingImgData {
    baseUrl = BingImgApi.baseUrl;
    url = "";

    data = {
        "images": [
            {
                "startdate": "",
                "fullstartdate": "",
                "enddate": "",
                "url": "",
                "urlbase": "",
                "copyright": "",
                "copyrightlink": "",
                "title": "",
                "quiz": "",
                "wp": false,
                "hsh": "",
                "drk": 0,
                "top": 0,
                "bot": 0,
                "hs": []
            }
        ],
        "tooltips": {
            "loading": "",
            "previous": "",
            "next": "",
            "walle": "",
            "walls": ""
        }
    }

    constructor(data) {
        console.log(data)
        if (!data) return;
        this.data = data;
        this.url = this.baseUrl + data.data.images.urlbase;
    }
}

/**
 * 必应图片api
 */
class BingImgApi {
    static baseUrl = "https://www.bing.com/";
    static api = "http://47.116.210.119:9300/BingImg/getData?format={format}&n={number}"
    static formatMap = {
        js: "js",
        other: ""
    }

    getData(cb, number, format) {
        const api = BingImgApi.api.replace("{format}", format || 'js').replace("{number}", number || '1');
        axios.get(api).then(res => {
            if (res && res.status === 200) {
                // const bingImgData = new BingImgData(res.data.data);
                cb && cb(res.data);
            }
        });
    }
}

export default new BingImgApi();
